/**@Title   GradeService.java
 * @Package com.gong.repository
 * @Desc    
 * @Author  GongWenhua
 * @Date    2017年7月17日 下午2:35:25
 * @Version 1.0
*/
package com.gong.service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.gong.bean.Grade;
import com.gong.repository.GradeRepository;
import com.gong.repository.GradeRepository2;
import com.gong.repository.GradeRepository3;

@Service
public class GradeService {
	
	@Resource
	private GradeRepository gradeRepository;
	
	@Resource
	private GradeRepository2 gradeRepository2;
	@Resource
	private GradeRepository3 gradeRepository3;
	
	public Grade findByGradeNum(String gradeNum){
		return gradeRepository.findByGradeNum(gradeNum);
	}
	
	public Grade findByGradeNumJPQL(String gradeNum){
		return gradeRepository.findByGradeNumJPQL(gradeNum);
	}
	
	@Transactional
	public void save(Grade grade){
		gradeRepository2.save(grade);
	}
	@Transactional
	public void delete(int id){
		gradeRepository2.delete(id);
	}
	
	
	public Iterable<Grade> findAll(){
		return gradeRepository3.findAll(new PageRequest(1, 2));
	}
	
	public Iterable<Grade> findAll2(){
		Sort sort = new Sort(Sort.Direction.DESC, "teacherId");
		return gradeRepository3.findAll(sort);
	}
}
